﻿Imports MySql.Data.MySqlClient
Public Class frmlogin
    Dim con As MySqlConnection
    Dim cmd As MySqlCommand
    Dim dbtable As DataTable
    Dim bsource As BindingSource
    Dim result As Integer
    Dim da As MySqlDataAdapter
    Private Sub frmlogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblwelcome.Enabled = False

    End Sub

    Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
        
        Dim con As New MySqlConnection
        con.ConnectionString = "server=localhost;userid=root;password=;database=library_database"
        Try
            con.Open()
            Dim query As String
            query = "select * from library_database.user_info where username='" & txtusername.Text & "' and password='" & txtpassword.Text & "'  "
            Dim cmd As New MySqlCommand(query, con)
            Dim reader As MySqlDataReader
            reader = cmd.ExecuteReader
            While reader.Read
                result = result + 1
            End While

            If result = 1 Then
                lblwelcome.Text = "WELCOME USER"
                MessageBox.Show("password and username is correct")

                MDIParent1.Show()
            Else
                MessageBox.Show("ano ka hacker?")
                lblwelcome.Enabled = False
                txtusername.Text = ""
                txtpassword.Text = ""
                txtusername.Focus()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            con.Close()
        End Try
    End Sub

    Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
        Application.ExitThread()
    End Sub

    Private Sub lblwelcome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblwelcome.Click

    End Sub
End Class
